if (!Date.now) {
    Date.now = function() { return new Date().getTime(); };
}


var currentTime = Date.now() || +new Date();
var qs = getQueryStrings();
var id = qs["id"];

var radiotype = qs["radiotype"];
var radiolink = qs["radiolink"];
var bcolor = qs["bcolor"];
var image = qs["image"];
var facebook = qs["facebook"];
var twitter = qs["twitter"];
var title = qs["title"];
var artist = qs["artist"];


setTimeout("processLast(qs);", 2000);


function getQueryStrings() { 
  var assoc  = {};
  var decode = function (s) { return decodeURIComponent(s.replace(/\+/g, " ")); };
  var queryString = location.search.substring(1); 
  var keyValues = queryString.split('&'); 

  for(var i in keyValues) { 
    var key = keyValues[i].split('=');
    if (key.length > 1) {
      assoc[decode(key[0])] = decode(key[1]);
    }
  } 

  return assoc; 
} 


//var qs = getQueryStrings();


//var first = getUrlVars()["me"];

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}


function RadioSongs(id){

     loadJS('http://html5radios.svnlabs.com/json/'+id+'.json?hash='+currentTime+'&_callback=processLast',false);
	
}







function loadJS(url,cache){
    //cache is true by default
    var s = document.createElement('script');
    s.type = 'text/javascript';
    s.src=url;
    if (cache==false) {
        s.src+='&jpt='+ (+new Date());
    }
    document.getElementsByTagName('head')[0].appendChild(s);
}


function processLast(qs){
	
	//console.log(feed.playlist.tracks.length);
	
	var radiotype = qs["radiotype"];
	var radiolink = qs["radiolink"];
	var bcolor = qs["bcolor"];
	var image = qs["image"];
	var facebook = qs["facebook"];
	var twitter = qs["twitter"];
	var title = qs["title"];
	var artist = qs["artist"];
	
	
	
	
		
	var currentTime = Date.now() || +new Date();
	
	
	
	
	
	//var img = (/(http|https)/i).test(image);
	
	//if(img) $("#current-play-pic").attr("src", image);
	
	//if(facebook)	$("#current-facebook").attr("href", facebook);
	//if(twitter) $("#current-twitter").attr("href", twitter);
	//if(artist) $("#current-artist").html("by "+artist);
	
	//$("#current-track").html(title);
	//$("#current-title").html(title);
	
		
	$("#WraperMainSmall").css("background-color", "#"+bcolor);
	
	if(bcolor=="ffffff" || bcolor=="fff" || bcolor=="FFFFFF" || bcolor=="FFF")
	{
		
	$("body").css("color", "#000000");
	
	$("#current-track").css("color", "#000000");
	$("#current-title").css("color", "#000000");
	$("#current-artist").css("color", "#000000");
	
	}
	
	callSlider();
	
}	



function SocialShareFB() 
{

 var str = $('#current-track').html();
 var currt = str.replace("&"," ");

 var atitle = encodeURI( "I listen to " + currt + " on Radio Stream" ); 
 var bhref = encodeURI(parent.document.location.href);
 
 //var url = 'https://www.facebook.com/sharer/sharer.php?u=';
 
 var url = 'http://www.facebook.com/sharer.php?s=100&p[title]='+atitle+'&p[url]='+bhref+'&p[images][0]='+mp3p+'&';
 
 window.open(url,"Mywindow","location=yes,menubar=yes");

}


function SocialShareTwitter() 
{

var str = $('#current-track').html();
 var currt = str.replace("&"," ");

var atitle = encodeURI( "I listen to " + currt + " on Radio Stream" ); 
 var bhref = encodeURI(parent.document.location.href);
 
 var url = 'https://twitter.com/intent/tweet?status='+atitle+' '+bhref+'&amp;url='+bhref;
 
 window.open(url,"Mywindow","location=yes,menubar=yes");




}



function callSlider()
{
	
//Store frequently elements in variables
var slider  = jQuery('#slider'),
	tool_tip = jQuery('.tool_tip');

//Hide the Tooltip at first
tool_tip.hide();

//Call the Slider
slider.slider({
	//Config
	range: "min",
	min: 0,
	value: volumez,

	start: function(event,ui) {
		tool_tip.fadeIn('fast');
	},

	//Slider Event
	slide: function(event, ui) { //When the slider is sliding

		var value  = slider.slider('value'),
			volume = jQuery('.vol_ume');

		tool_tip.css('left', value).text(ui.value);  //Adjust the tooltip accordingly
		
		jQuery("#jquery_jplayer_1").jPlayer("volume", ui.value / 100);

		if(value <= 5) { 
			volume.css('background-position', '0 0');
		} 
		else if (value <= 25) {
			volume.css('background-position', '0 -25px');
		} 
		else if (value <= 75) {
			volume.css('background-position', '0 -50px');
		} 
		else {
			volume.css('background-position', '0 -75px');
		};

	},

	stop: function(event,ui) {
		tool_tip.fadeOut('fast');
	}
});	
	
}
